package com.example.book.in.controller;

import com.example.book.base.BaseController;
import com.example.book.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.example.book.in.entity.BookPopularity;
import com.example.book.in.service.BookPopularityService;


/**
 * @author   hcj
 * @date 2019-12-10 16:02:03
*/
@Controller
@RequestMapping(value = "/bookPopularity")
public class BookPopularityController extends BaseController{

    @Autowired
    private BookPopularityService bookPopularityService;

    @ModelAttribute
    public BookPopularity get(@RequestParam(required=false) String id) {
        if (StringUtils.isNotBlank(id)){
            BookPopularity bookPopularity = new BookPopularity();
            bookPopularity.setId(id);
            return bookPopularityService.get(bookPopularity);
        }else{
            return new BookPopularity();
        }
    }

    @RequestMapping(value = "/get")
    @ResponseBody
    public BookPopularity getById(BookPopularity bookPopularity) {
        return bookPopularity;
    }

    @RequestMapping(value = "/list")
    public String list(BookPopularity bookPopularity) {
        return "bookPopularity";
    }

    @RequestMapping(value = "/info")
    @ResponseBody
    public List<BookPopularity> info(BookPopularity bookPopularity) {
        return bookPopularityService.findList(bookPopularity);
    }


    @RequestMapping(value = "/findPage")
    @ResponseBody
    public PageInfo<BookPopularity> findPage(BookPopularity bookPopularity) {
        return  bookPopularityService.findPage( bookPopularity);
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Result save(BookPopularity bookPopularity) {
        bookPopularityService.save(bookPopularity);
        return Result.success("保存成功");
    }

    @RequestMapping(value = "/logicalDeletion",method = RequestMethod.POST)
    @ResponseBody
    public Result logicalDeletion(@RequestParam("id") String id){
        bookPopularityService.logicalDeletion(id);
        return Result.success();
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam("ids") String[] ids){
        bookPopularityService.delete(ids);
        return Result.success();
    }

}